<template>
  <div class="datail">
    <div class="v-hd2">
      <router-link to="#" class="new">榜单</router-link>
      <span class="more">
        <a href="#" class="s-fc3">更多</a>
        <i class="cor">&nbsp;</i>
      </span>
    </div>
    <div class="inner" v-if="viewFlag">
      <div class="blk" v-for="(item, index) in playlist" :key="index">
        <div class="top">
          <a href="JavaScript:;" class="top-a">
             <img :src="item.coverImgUrl" alt="" />
          </a>
           <div class="tit">
            <a href="JavaScript:;" class="tit-a">
              <h3>{{ item.name }}</h3>
            </a>
            <div class="btn">
              <a href="JavaScript:;"></a>
              <a href="JavaScript:;"></a>
            </div>
          </div>
        </div>
         <div class="dd" >
           <ul>
             <li
              v-for="(p_item , p_index) in item.playlistData"
              :key="p_index"
            >
              <span>{{ p_index}}</span> 
              <router-link :to="{path:'/home/song' , query:{id :p_item.id}}" :id="item.id" class="text">{{ p_item.name }}</router-link>
              <div class="oper" v-show="true">
                <a
                  href="javascript:;"
                  class="s-bg s-bg-11"
                  title="播放"
                  @click="sendID(p_item.id , $event)"
                ></a>
                <a
                  href="javascript:;"
                  class="s-bg s-bg-12"
                  title="收藏"
                ></a>
              </div>
            </li>
          </ul> 
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from 'axios';
import { playlist_detail } from "../../../network/login"; //获取各榜 的歌曲列表
export default {
  data() {
    return {
      playlist: [],
      flag: null,
      viewFlag:false
    };
  },
  methods: {
      sendID(id ,e){
         this.$store.dispatch("music_ct",{music_id:id , pageY:e.pageY})
      },
      playlistData(data){
        var apis = []
        data.forEach( item => {
           var obj ={}
           obj.name = item.name,
           obj.coverImgUrl = item.coverImgUrl
          const oneAPI = playlist_detail(item.id).then(res => {
           obj.playlistData = res.data.playlist.tracks.slice(0,10)
             return obj
           })
           apis.push(oneAPI)
        });
        Promise.all(apis).then(res => {
            this.playlist = res
            this.viewFlag = true
        })
      }
  },
 watch:{
    '$store.state.toplistSidebarData': function(value){
        this.playlistData( value.slice(0,3))
    }
 },
  created() {
   this.$store.dispatch("toplist")
  },
};
</script>

<style scoped>
.datail {
    display: block;
}
.v-hd2 {
  height: 33px;
  padding: 0 10px 0 34px;
  border-bottom: 2px solid #c10d0c;
  background: url("../../../assets/imgs/index.png") no-repeat;
  background-position: -225px -156px;
}
.new {
  display: block;
  line-height: 28px;
  font-weight: normal;
  font-size: 20px;
  float: left;
}
.more {
  float: right;
  margin-top: 6px;
}
.more a {
  color: #666;
  font-size: 12px;
}
.inner {
  min-height: 472px;
  border: 1px solid #fff;
  margin: 30px 0px 2px 0px;
  position: relative;
  background: url("https://s2.music.126.net/style/web2/img/index/index_bill.png?85b71e66297ddf079a51a549dc4c46f8")
    no-repeat;
  background-size: 686px 474px;
}
.inner .blk {
  width: 229px;
  float: left;
}
.inner .top {
  padding: 20px 0 0 19px;
  height: 100px;
}
.inner .top .top-a {
  display: block;
  width: 80px;
  height: 80px;
  float: left;
}
.inner .top a img {
  width: 100%;
  height: 100%;
}
.top .tit {
  width: 116px;
  margin: 6px 0 0 10px;
  float: left;
}
.tit .tit-a {
  height: 18px;
  display: block;
}
.tit .tit-a h3 {
  font-size: 14px;
  color: #333;
  font-family: Arial, Helvetica, sans-serif;
  padding: 0px;
  margin: 0px;
}
.top .btn {
  margin-top: 10px;
}
.top .btn a {
  display: block;
  float: left;
  width: 22px;
  height: 22px;
  margin-right: 10px;
}
.top .btn a:nth-child(1) {
  background: url("../../../assets/imgs/index.png") no-repeat;
  background-position: -267px -205px;
}
.top .btn a:nth-child(1):hover {
  background-position: -267px -235px;
}
.top .btn a:nth-child(2) {
  background: url("../../../assets/imgs/index.png") no-repeat;
  background-position: -300px -205px;
}
.top .btn a:nth-child(2):hover {
  background-position: -300px -235px;
}
.inner .dd {
  width: 100%;
}
.dd ul {
  height: 322px;
  margin-left: 50px;
  line-height: 32px;
}
.dd ul li {
   height: 32px;
}
.dd ul li:hover :nth-child(3){
    opacity: 1;
}
.dd ul span {
  float: left;
  width: 35px;
  line-height: 32px;
  margin-left: -35px;
  text-align: center;
  color: #666;
  font-size: 15px;
}
.dd ul .text {
  float: left;
  width: 114px;
  
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  word-wrap: normal;
  font-size: 12px;
  font-family: Arial, Helvetica, sans-serif;
}
.dd ul .text:hover {
  text-decoration: underline;
}
.dd ul .text i {
  display: block;
  position: absolute;
  right: 0px;
  top: 13px;
  width: 17px;
  height: 17px;
  background: url("../../../assets/imgs/index.png") no-repeat 0 9999px;
  background-position: -267px -268px;
}
/* .s-bg,
.v-hd2,
.n-disk li {
  background: url("../../../assets/imgs/index.png") no-repeat 0 9999px;
} */
.s-bg-11 {
  background-position: -267px -268px;
}
 ul .oper {
    display: block;
    float: right;
    width: 54px;
    margin-top: 7px;
    opacity: 0;
}
ul .oper a {
    float: left;
    width: 17px;
    height: 17px;
    margin-right: 10px;
}
.s-bg{
    background: url("../../../assets/imgs/index.png") no-repeat 0 9999px;
}
.s-bg-11 {
    background-position: -267px -268px;
}
.s-bg-12 {
    background-position: -297px -268px;
}
</style>